<?php
namespace Common\Model;
class GongyituModel extends BaseModel {

    //追加属性
    public $append = [
        'cate_name',//分类名称
    ];

    function getCateNameAttr($value, $data){
        $kwp_model = M('imgcate');
        $kwp_wdata['id'] = $data['cate_id'];
        $title = $kwp_model->where($kwp_wdata)->getField('title');
        return $title;
    }
     //搜索
   function _search(){
        $map = [];
        if(I('keyword')){
            $map['title|codes'] = array('like', '%' . I('keyword'). '%');
        }
        $map['is_delete'] = I('is_delete') ? : 0;
        $cat_id=I('cate_id');
        if($cat_id){
            $dra[]=$cat_id;
            //查询子分类
            $i_model = M('Imgcate');
            $spec_list = $i_model->field('id')->where(['pid'=>$cat_id])->select();
            if($spec_list){
              foreach($spec_list as $k=>$val){
                 $dra[]=$val['id'];
              }
            }
            $map['cate_id']=['in',$dra];
        }
        return $map;
    }

   
}

?>